package com.my.serviceimpl;

import com.alibaba.fastjson.JSONObject;
import com.my.bean.ResultPage;
import com.my.bean.SituationAnalysis;
import com.my.bean.VoPage;
import com.my.mapper.SituationAnalysisMapper;
import com.my.service.SituationAnalysisService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.my.util.SessionUtil;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 客户情况分析 服务实现类
 * </p>
 *
 * @author 冯政尚
 * @since 2018-09-07
 */
@Service
public class SituationAnalysisServiceImpl extends ServiceImpl<SituationAnalysisMapper, SituationAnalysis> implements SituationAnalysisService {


    //实现分页查询
    @Override
    public ResultPage<SituationAnalysis> selectMyPage(Map map, VoPage voPage, HttpSession session,Long areaid,boolean admin) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1)*voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        paramMap.put("userId", SessionUtil.getSessionUser(session).getId());
        List<SituationAnalysis> list = baseMapper.selectMyPage(map,paramMap,areaid,admin);
        Integer count = baseMapper.countMyPage(map,paramMap,areaid,admin);
        ResultPage<SituationAnalysis> resultPage=new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }



    //实现分页查询  每个销售每个月的总单数
    @Override
    public ResultPage<SituationAnalysis> selectCount(Map map, VoPage voPage,Long areaid,boolean admin) {
        Map<String, Object> paramMap = new HashMap<String, Object>();
        paramMap.put("page", (voPage.getPage() - 1)*voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        List<SituationAnalysis> list = baseMapper.selectCount(map,paramMap,areaid,admin);
        Integer count = baseMapper.count(map,paramMap,areaid,admin);
        ResultPage<SituationAnalysis> resultPage=new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }

    /**
     * 根据录入人查询
     * @param
     * @return
     */
    @Override
    public ResultPage<SituationAnalysis> selectByPerson(VoPage voPage,String person,Long areaid,boolean admin) {
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", (voPage.getPage() - 1)*voPage.getLimit());
        paramMap.put("limit", voPage.getLimit());
        paramMap.put("person", person);
        List<SituationAnalysis> list = baseMapper.selectByPerson(paramMap,areaid,admin);
        Integer count = baseMapper.countPerson(paramMap,areaid,admin);
        ResultPage<SituationAnalysis> resultPage=new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }

}
